package com.example.seckill.activemq;

import com.example.seckill.dao.GoodsMapper;
import com.example.seckill.dao.GoodsRecordMapper;
import com.example.seckill.entity.GoodsRecord;
import com.example.seckill.service.IGoodsRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *  @Author: caesar
 *  @Date：2020年12月08日 20:12:44
 *  @Description: 消费者
 */
@Service
public class MQReceiver {
    private static final Logger logger = LoggerFactory.getLogger(MQReceiver.class);
    @Autowired
    private GoodsRecordMapper goodsRecordMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    private static final long now = System.currentTimeMillis();
    @RabbitListener(queues= "GOODS_QUEUE")//指明监听的是哪一个queue
    public void receive(GoodsRecord goodsRecord){
        logger.info("正在接收消息。。。。+入库时间为"+(System.currentTimeMillis()-now));
        goodsRecordMapper.insertGoodsRecord(goodsRecord);
        // 更新库存
        goodsMapper.updateGoods(goodsRecord);
    }
}
